// import cFoot from "../enterprise_wechat/myComponents/foot";
import userInfo from "../../enterprise_wechat/myComponents/memberInfo";
import myCustomer from "../../enterprise_wechat/myComponents/my_customer";
import orderList from "../../enterprise_wechat/myComponents/orderList";
import revenueDetails from "../../enterprise_wechat/myComponents/revenueDetails";
import myCart from "../../enterprise_wechat/myComponents/myCart";
import goodsCoupon from '../../enterprise_wechat/myComponents/goodsCoupon';
import myFavorite from '../../enterprise_wechat/myComponents/myFavorite';
import browseRecord from '../../enterprise_wechat/myComponents/browseRecord';
import { Toast } from 'vant';


export default {
  data () {
    return {
      agentData: { // 企业微信config接口配置
        agent_secret: "",
        agentid: "",
        corpid: ""
      },
      testUserId: 'wmDesSDgAAnVOxcNIw8XQ6x1qhN5ZidA', // dev15 测试userId
      userDataUrl: "plugin.customer-center.frontend.controllers.customer.get-customer",
      getConfig: {member_id: '',income_statistic_type: 0}, //企业微信公共参数

      memberInfo: {}, // 会员信息
      income_statistic: [], // 收入信息
      tags: [], // 标签列表
      actions: [], // 企业标签
      navActive: 0,
      addTagText: '',
      showAddTagPop: false,
      showAddSheet: false,
      income_statistic_type: "0",

      tabList: ['会员详情', 'Ta的客户', '订单列表', '收入详情', 'Ta的购物车', '优惠券', '商品收藏', '浏览足迹'],
      showChild: false,
      subjectColor:''
    };
  },
  computed: {
    componentName () {
      switch (this.navActive) {
      case 1:
        return "myCustomer";
      case 2:
        return "orderList";
      case 3:
        return "revenueDetails";
      case 4:
        return "myCart";
      case 5:
        return "goodsCoupon";
      case 6:
        return "myFavorite";
      case 7:
        return "browseRecord";
      }
    },
  },
  activated () {
    this.getConfig.member_id = this.$route.params.id
    this.getUserData();
    try {
      this.subjectColor = JSON.parse(localStorage.getItem("yz_basic_info")).theme_color;
    } catch (error) {
      console.log(error)
    }
    // this.getAgentConfig();

    // if (this.fun.getTyep() === "17") {
    //   this.getAgentConfig();
    // } else {
    //   // // 本地测试 start
    //   this.getCustomerInfo(this.testUserId);
    //   // // 本地测试 end
    // }
  },

  methods: {
    getUserData () {
      $http.post(this.userDataUrl, this.getConfig, "loading").then(res => {
        if (res.result === 1) {
          if (res.data.member && res.data.member.hasAuth == 0) {
            this.$dialog.alert({ message: "暂无权限" })
              .then(() => {
                this.$router.push(this.fun.getUrl("member"));
              });
          }
          this.showChild = true;
          this.tags = res.data.member.has_many_tag;
          this.memberInfo = res.data.member;
          this.income_statistic = res.data.statistics;
        } else {
          this.$toast(res.msg);
        }
      }).catch(err => {
        console.log('getUserData::err',err);
      });
    },
    closeSheet () {
      this.showAddSheet = false;
    },
    beforeClose(action, done) {
      if (action === 'confirm') {
        let _countTimer = setInterval(() => {
          this.countTime -= 1;
          if(this.countTime == 0){
            clearInterval(_countTimer);
            done();
          }
        }, 1000);
      } else {
        done();
      }
    },
    selectTime () {
      console.log('ddddddddddd')
      $http.get(this.userDataUrl, {...this.getConfig,income_statistic_type:this.income_statistic_type}, "loading").then(res => {
        if (res.result === 1) {
          this.income_statistic = res.data.statistics;
        } else {
          this.$toast(res.msg);
        }
      }).catch(err => {
        console.log(err);
      });
    },

    // 跳转至会员权益
    gotoMemberGrade() {
      if (this.isMemberGrade) {
        this.$router.push(this.fun.getUrl("MemberGradeList"));
      }
    },
    // 跳转至名片
    toCard(id) {
      if (!id) {
        Toast("该会员没有对应的名片");
        return;
      }
      this.$router.push(this.fun.getUrl("BusinessCard",{},{ mark_id: id, mark: "card" }));
    },

    // 错误日志
    errorLogHandler (logType, err) {
      $http.get('plugin.wechat-chat-sidebar.frontend.controller.index.recordErrorLog', {logType, err}, "loading")
        .then()
        .catch(err => {
          console.log(err);
        });
    }
  },

  components: {
    // cFoot,
    userInfo,
    myCustomer,
    orderList,
    revenueDetails,
    myCart,
    goodsCoupon,
    myFavorite,
    browseRecord
  },
};
